[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Titles.MinimizeButton.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Controls.Titles.MinimizeButton.debug.js", "application/x-javascript")]

namespace BM.Tools.WebControls.MForm.Controls.Titles
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using AjaxControlToolkit;

    using BM.Tools.WebControls.MForm.ScriptReferences;

    /// <summary>
    /// A control that displays an image for minimization or maximization
    /// </summary>
    [DesignTimeVisible(false)]
    [ClientScriptResource("BM.Tools.WebControls.MForm", "BM.Tools.WebControls.MForm.Controls.Titles.MinimizeButton.js")]
    public class MinimizeButton : WebControl
    {
        private const string MinimizeButtonCssClass = "MForm-Btn MForm-";

        /// <summary>
        /// Gets or sets a value indicating whether Collapsed.
        /// </summary>
        /// <value>
        /// The collapsed.
        /// </value>
        public bool Collapsed
        {
            get;
            set;
        }

        /// <summary>
        /// Gets CollapsedModifier.
        /// </summary>
        /// <value>
        /// The collapsed modifier.
        /// </value>
        protected virtual string CollapsedModifier
        {
            get
            {
                if (Collapsed)
                {
                    return "ToggleDownBtn";
                }

                return "ToggleUpBtn";
            }
        }

        /// <summary>
        /// The img tag key
        /// </summary>
        /// <value>
        /// The tag key.
        /// </value>
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.A;
            }
        }

        /// <summary>
        /// adds custom attributes to the image
        /// </summary>
        /// <param name="writer">
        /// A <see cref="T:System.Web.UI.HtmlTextWriter"></see> that represents the output stream to render HTML content on the client. 
        /// </param>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);                        
            writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "BM.MinimizeButton.showHideSection(this);");
        }

        /// <summary>
        /// Include resources.
        /// </summary>
        /// <param name="e">
        /// The event args.
        /// </param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            CssClass = MinimizeButtonCssClass + CollapsedModifier;
            ScriptIncluder.IncludeResources(this);
        }
    }
}